package com.skyworth.web.admin.role.repository;

import com.skyworth.web.admin.role.domain.RoleModel;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * Created by lxs on 2016/9/22.
 */
public interface RoleRepo extends PagingAndSortingRepository<RoleModel, Long> {

	@Query("SELECT CASE WHEN COUNT(role) > 0 THEN 'true' ELSE 'false' END FROM RoleModel role WHERE role.name = ?1 and role.storeId=?2")
	boolean existByName(String name, long store_id);

	@Query("select role from RoleModel role where role.storeId=?1")
	Page<RoleModel> findAllByStoreId(long store_id, Pageable pageable);

	@Query("select role from RoleModel role where  role.storeId=?1")
	List<RoleModel> findByStoreId(long store_id);

}
